<?php

namespace apiend\modules\shop\models;

use Yii;
use common\helpers\Url;
use common\helpers\ArrayHelper;
use yii\data\ActiveDataProvider;
use common\models\shop\ShopAttachment;
use apiend\modules\shop\models\ShopGoodsSales;
use common\models\shop\ShopGoods;
use common\models\shop\ShopProduct;

class ShopGoodsDetail extends \common\models\shop\ShopProduct {

    public $product_id;
    public $goods_id;

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['goods_id','product_id'], 'integer'],
        ];
    }

    public function getPrice()
    {
       return ShopGoods::findOne(['id' => $this->goods_id]);
    }

    /**
     * {@inheritdoc}
     */
    public function search($params = [])
    {
        
        $product = static::findOne(['id' => $this->product_id]);
        $goods =  ShopGoods::findOne(['id' => $this->goods_id]);
        return [
            'ab' => $product,
            '11' => $goods,
        ];
    }

    public function fields() {
        return [
            'id',
            'name',
            'thumb' => function() {
                return Url::attach($this->cover);
            },
            'slogan',
            'price',
            // 'description',
            'price' => 'price',
            // 'sales' => 'sales',
            // 'sku' =>  function() {
            //     return '';
            // },
            // 'album' => 'album',
        ];
    }

}
